package yz.cp.back.admin.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import yz.cp.back.s.entity.SysDepartment;
import yz.cp.back.s.service.ISysDepartmentService;

import java.util.List;

@Service
public class DepartmentManage {
    @Autowired
    private UserManage userManage;
    @Autowired
    private ISysDepartmentService departmentService;

    public List<SysDepartment> findByParentIdOrderBySortOrder(String parentId, Boolean openDataFilter) {
        // 数据权限
        List<String> depIds = userManage.getDepartmentIds();
        if (depIds != null && depIds.size() > 0 && openDataFilter) {

            return departmentService.findByParentIdAndIdInOrderBySortOrder(parentId, depIds);
        }
        return departmentService.findByParentIdOrderBySortOrder(parentId);
    }

    public List<SysDepartment> findByParentIdAndStatusOrderBySortOrder(String parentId, Integer status) {

        return departmentService.findByParentIdAndStatusOrderBySortOrder(parentId, status);
    }


    public List<SysDepartment> findByTitleLikeOrderBySortOrder(String title, Boolean openDataFilter) {

        // 数据权限
        List<String> depIds =  userManage.getDepartmentIds();
        if (depIds != null && depIds.size() > 0 && openDataFilter) {
            return departmentService.findByTitleLikeAndIdInOrderBySortOrder(title, depIds);
        }
        return departmentService.findByTitleLikeOrderBySortOrder(title);
    }
}
